package com.edu.exam.entity.grading.correction;

import com.edu.exam.enums.grading.VersionType;
import com.edu.exam.enums.grading.VersionStatus;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

import jakarta.persistence.*;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import jakarta.validation.constraints.Size;
import java.time.LocalDateTime;

/**
 * 修正版本实体类
 * 所属模块：E-02 阅卷管理模块
 * 对应数据库表：correction_version
 *
 * 记录成绩修正的版本信息，包括版本号、版本内容、
 * 版本描述等关键信息。支持修正过程的版本控制和回溯。
 *
 * @author System
 * @version 1.0.0
 */
@Entity
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class CorrectionVersion {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @NotNull(message = "修正ID不能为空")
    @Column(name = "correction_id", nullable = false)
    private Long correctionId;

    @NotBlank(message = "版本号不能为空")
    @Size(max = 20, message = "版本号长度不能超过20个字符")
    @Column(name = "version_number", nullable = false, length = 20)
    private String versionNumber;

    @NotNull(message = "版本内容不能为空")
    @Column(name = "version_content", nullable = false, columnDefinition = "TEXT")
    private String versionContent;

    @Size(max = 1000, message = "版本描述长度不能超过1000个字符")
    @Column(name = "version_description", columnDefinition = "TEXT")
    private String versionDescription;

    @NotNull(message = "创建人ID不能为空")
    @Column(name = "creator_id", nullable = false)
    private Long creatorId;

    @Size(max = 100, message = "创建人姓名长度不能超过100个字符")
    @Column(name = "creator_name", length = 100)
    private String creatorName;

    @NotNull(message = "创建时间不能为空")
    @CreationTimestamp
    @Column(name = "creation_time", nullable = false, updatable = false)
    private LocalDateTime creationTime;

    @Enumerated(EnumType.STRING)
    @Column(name = "version_type", length = 20)
    @Builder.Default
    private VersionType versionType = VersionType.MAJOR;

    @Enumerated(EnumType.STRING)
    @Column(name = "version_status", length = 20)
    @Builder.Default
    private VersionStatus versionStatus = VersionStatus.ACTIVE;

    @Size(max = 1000, message = "版本备注长度不能超过1000个字符")
    @Column(name = "version_remarks", columnDefinition = "TEXT")
    private String versionRemarks;

    @Column(name = "is_current_version", nullable = false)
    @Builder.Default
    private Boolean isCurrentVersion = false;

    @Column(name = "deleted", nullable = false)
    @Builder.Default
    private Boolean deleted = false;

    @UpdateTimestamp
    @Column(name = "update_time", nullable = false)
    private LocalDateTime updateTime;

    @Column(name = "create_user", nullable = false)
    private Long createUser;

    @Column(name = "update_user", nullable = false)
    private Long updateUser;

}